<template>
  <div class="system-role-dialog-container">
    <el-dialog
      :title="state.dialog.title"
      @open="openDialogLs"
      @close="closeDialog"
      v-model="state.dialog.isShowDialog"
      width="769px"
    >
      <div class="el-form-ls">
        <el-form
          class="el-form-new"
          ref="roleDialogFormRef"
          :rules="rules"
          :model="state.ruleForm"
          size="default"
          label-width="140px"
        >
          <el-row :gutter="35">
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="组合项目名称：" prop="ZuHeXiangMuMingCheng">
                <el-input
                  ref="ZuHeXiangMuMingChengRef"
                  @keydown.enter="ZuHeXiangMuMingChengKey"
                  v-model="state.ruleForm.ZuHeXiangMuMingCheng"
                  placeholder="请输入组合项目名称"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="单价：" prop="DanJia">
                <el-input
                  ref="DanJiaRef"
                  @keydown.enter="DanJiaKey"
                  v-model="state.ruleForm.DanJia"
                  @input="inputChangeLs(state.ruleForm.DanJia, 'DanJia')"
                  placeholder="请输入单价"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="优惠价：" prop="YouHuiJia">
                <el-input
                  ref="YouHuiJiaRef"
                  @keydown.enter="YouHuiJiaKey"
                  @input="inputChangeLs(state.ruleForm.YouHuiJia, 'YouHuiJia')"
                  v-model="state.ruleForm.YouHuiJia"
                  placeholder="请输入优惠价"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <!--              todo ChengBenJia   ChengBenJian 查询的和新增的字段不一样-->
              <el-form-item label="成本价：" prop="ChengBenJian">
                <el-input
                  ref="ChengBenJianRef"
                  @keydown.enter="ChengBenJianKey"
                  @input="inputChangeLs(state.ruleForm.ChengBenJian, 'ChengBenJian')"
                  v-model="state.ruleForm.ChengBenJian"
                  placeholder="请输入成本价"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="科室分成价：" prop="KeShiFenChengJia">
                <el-input
                  ref="KeShiFenChengJiaRef"
                  @input="inputChangeLs(state.ruleForm.KeShiFenChengJia, 'KeShiFenChengJia')"
                  @keydown.enter="KeShiFenChengJiaKey"
                  v-model="state.ruleForm.KeShiFenChengJia"
                  placeholder="请输入科室分成价"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="适用性别：" prop="ShiYongXingBie">
                <el-select
                  ref="ShiYongXingBieRef"
                  v-model="state.ruleForm.ShiYongXingBie"
                  class="m-2"
                  clearable
                  placeholder="请选择适用性别"
                >
                  <el-option v-for="item in genderType" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="拼音码：" prop="PYM">
                <el-input
                  ref="PYMRef"
                  @keydown.enter="PYMKey"
                  v-model="state.ruleForm.PYM"
                  placeholder="请输入拼音码"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="所属报告分类：" prop="BaoGaoSuoShuFenLei">
                <el-select
                  ref="BaoGaoSuoShuFenLeiRef"
                  v-model="state.ruleForm.BaoGaoSuoShuFenLei"
                  class="m-2"
                  placeholder="请选择所属报告分类"
                >
                  <el-option v-for="item in baoGaoType" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="提示信息：" prop="TiShiXinXi">
                <el-input
                  ref="TiShiXinXiRef"
                  @keydown.enter="TiShiXinXiKey"
                  v-model="state.ruleForm.TiShiXinXi"
                  placeholder="请输入提示信息"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="正常描述：" prop="ZhengChangMiaoShu">
                <el-input
                  ref="ZhengChangMiaoShuRef"
                  @keydown.enter="ZhengChangMiaoShuKey"
                  v-model="state.ruleForm.ZhengChangMiaoShu"
                  placeholder="请输入正常描述"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="默认检查者：" prop="MoRenJianChaZhe">
                <el-input
                  ref="MoRenJianChaZheRef"
                  @keydown.enter="MoRenJianChaZheKey"
                  v-model="state.ruleForm.MoRenJianChaZhe"
                  placeholder="请输入检查类别"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="默认审核者：" prop="MoRenShenHeZhe">
                <el-input
                  ref="MoRenShenHeZheRef"
                  @keydown.enter="MoRenShenHeZheKey"
                  v-model="state.ruleForm.MoRenShenHeZhe"
                  placeholder="请输入备注1"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="医学名称：" prop="YiXueMingCheng">
                <el-input
                  ref="YiXueMingChengRef"
                  @keydown.enter="YiXueMingChengKey"
                  v-model="state.ruleForm.YiXueMingCheng"
                  placeholder="请输入医学名称"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="医学简码：" prop="YiXueJianMa">
                <el-input
                  ref="YiXueJianMaRef"
                  @keydown.enter="YiXueJianMaKey"
                  v-model="state.ruleForm.YiXueJianMa"
                  placeholder="请输入医学简码"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="外接编码：" prop="WaiJieBianMa">
                <el-input
                  ref="WaiJieBianMaRef"
                  @keydown.enter="WaiJieBianMaKey"
                  v-model="state.ruleForm.WaiJieBianMa"
                  placeholder="请输入外接编码"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="HIS科室代码：" prop="HISKeShiDaiMa">
                <el-input
                  ref="HISKeShiDaiMaeRef"
                  @keydown.enter="HISKeShiDaiMaKey"
                  v-model="state.ruleForm.HISKeShiDaiMa"
                  placeholder="请输入HIS科室代码"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="费用类别：" prop="FeiYongLeiBie">
                <el-select ref="FeiYongLeiBieRef" v-model="state.ruleForm.FeiYongLeiBie" class="m-2" placeholder="请选择费用类别">
                  <el-option v-for="item in feiYongLeiBieType" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="HIS科室名称：" prop="HISKeShiMingCheng">
                <el-input
                  ref="HISKeShiMingChengRef"
                  @keydown.enter="HISKeShiMingChengKey"
                  v-model="state.ruleForm.HISKeShiMingCheng"
                  placeholder="请输入HIS科室名称"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="国标代码：" prop="GuoBiaoDaiMa">
                <el-input
                  ref="GuoBiaoDaiMaRef"
                  @keydown.enter="GuoBiaoDaiMaKey"
                  v-model="state.ruleForm.GuoBiaoDaiMa"
                  placeholder="请输入国标代码"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="上级国标代码：" prop="ShangJiGuoBiaoDaiMa">
                <el-input
                  ref="ShangJiGuoBiaoDaiMaRef"
                  @keydown.enter="ShangJiGuoBiaoDaiMaKey"
                  v-model="state.ruleForm.ShangJiGuoBiaoDaiMa"
                  placeholder="请输入国标代码"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="所属院区：" prop="SuoShuYuanQu">
                <el-select
                  ref="SuoShuYuanQuRef"
                  multiple
                  collapse-tags
                  collapse-tags-tooltip
                  v-model="state.ruleForm.SuoShuYuanQu"
                  class="m-2"
                  placeholder="请选择所属院区"
                >
                  <el-option v-for="item in yuanQuType" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="备注1：" prop="BeiZhu1">
                <el-input
                  ref="BeiZhu1Ref"
                  @keydown.enter="BeiZhu1Key"
                  v-model="state.ruleForm.BeiZhu1"
                  placeholder="请输入备注1"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <!--          分界-->
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="备注2：" prop="BeiZhu2">
                <el-input
                  ref="BeiZhu2Ref"
                  @keydown.enter="BeiZhu2Key"
                  v-model="state.ruleForm.BeiZhu2"
                  placeholder="请输入备注2"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="备注3：" prop="BeiZhu3">
                <el-input
                  ref="BeiZhu3Ref"
                  @keydown.enter="BeiZhu3Key"
                  v-model="state.ruleForm.BeiZhu3"
                  placeholder="请输入备注3"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
              <el-form-item label="上级国标名称：" prop="ShangJiGuoBiaoMingCheng">
                <el-input
                  ref="ShangJiGuoBiaoMingChengRef"
                  @keydown.enter="ShangJiGuoBiaoMingChengKey"
                  v-model="state.ruleForm.ShangJiGuoBiaoMingCheng"
                  placeholder="请输入上级国标名称"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
              <el-form-item label="检查指标意义：" prop="JianChaZhiBiaoYiYi">
                <el-input
                  ref="JianChaZhiBiaoYiYiRef"
                  @keydown.enter="JianChaZhiBiaoYiYiKey"
                  v-model="state.ruleForm.JianChaZhiBiaoYiYi"
                  placeholder="请输入检查指标意义"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col style="margin-left: 100px" :xs="4" :sm="4" :md="4" :lg="4" :xl="4" class="mb20">
              <el-form-item label="" class="switch-all" prop="ShiFouQiYong">
                <el-switch
                  ref="ShiFouQiYongRef"
                  v-model="state.ruleForm.ShiFouQiYong"
                  class="ml-2 switch-ls"
                  inline-prompt
                  active-text="启用状态"
                  inactive-text="禁用状态"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="4" :sm="4" :md="4" :lg="4" :xl="4" class="mb20">
              <el-form-item label="" class="switch-all" prop="ShiFouZongjianZhanShi">
                <el-switch
                  v-model="state.ruleForm.ShiFouZongjianZhanShi"
                  class="ml-2 switch-ls"
                  inline-prompt
                  active-text="总检展示"
                  inactive-text="总检不展示"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="4" :sm="4" :md="4" :lg="4" :xl="4" class="mb20">
              <el-form-item label="" class="switch-all" prop="ShiFouWeiXinZhanShi">
                <el-switch
                  v-model="state.ruleForm.ShiFouWeiXinZhanShi"
                  class="ml-2 switch-ls"
                  inline-prompt
                  active-text="允许微信展示"
                  inactive-text="微信不展示"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="4" :sm="4" :md="4" :lg="4" :xl="4" class="mb20">
              <el-form-item label="" class="switch-all" prop="ShiFouZaiFenJianXianShiMingXi">
                <el-switch
                  v-model="state.ruleForm.ShiFouZaiFenJianXianShiMingXi"
                  class="ml-2 switch-ls"
                  inline-prompt
                  active-text="分检显示明细"
                  inactive-text="分检不显示明细"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="4" :sm="4" :md="4" :lg="4" :xl="4" class="mb20">
              <el-form-item label="" class="switch-all" prop="ShiFouDaoRuWaiJie">
                <el-switch
                  v-model="state.ruleForm.ShiFouDaoRuWaiJie"
                  class="ml-2 switch-ls"
                  inline-prompt
                  active-text="导入外接"
                  inactive-text="不导入外接"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="onCancel" size="default">取 消</el-button>
          <el-button type="primary" @click="onSubmit" size="default">{{ state.dialog.submitTxt }}</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { nextTick, reactive, ref, watch } from "vue";
import { baoGaoType, genderType } from "@/utils/dict";
import { deepCopy, useFocusInput } from "@/utils";
import { useIntegratedProject } from "@/stores/modules/integratedProject";
import { GetFeiYongLeiBieSel, PostZuHeXiangMuAdd, PutZuHeXiangMuUpdate } from "@/api/modules/integratedProject";
import { ElMessage } from "element-plus";
import { pinyin } from "pinyin-pro";
import { GetAllYuanQuSel } from "@/api/modules/pulbic";
// 定义子组件向父组件传值/事件
const emit = defineEmits(["refresh"]);

const rules = reactive({
  ZuHeXiangMuMingCheng: [{ required: true, message: "请输入组合项目名称" }],
  SuoShuYuanQu: [{ required: true, message: "请选择所属院区" }],
  BaoGaoSuoShuFenLei: [{ required: true, message: "请选择所属报告分类" }],
  DanJia: [{ required: true, message: "请输入单价" }],
  ShiYongXingBie: [{ required: true, message: "请选择适用性别" }]

  // ShiFouWeiXinZhanShi: [{ required: true, message: "请选择是否微信展示" }],
  // ShiFouZongjianZhanShi: [{ required: true, message: "请选择是否总检展示" }],
  // ShiFouQiYong: [{ required: true, message: "请选择是否启用" }],
  // ShiFouZaiFenJianXianShiMingXi: [{ required: true, message: "请选择是否显示分检明细" }],
  // ShiFouDaoRuWaiJie: [{ required: true, message: "请选是否导入外接" }]
});

// 定义变量内容
const roleDialogFormRef = ref<any>();
const state = reactive<any>({
  ruleForm: {
    ShiFouQiYong: false,
    ShiFouWeiXinZhanShi: false,
    ShiFouZongjianZhanShi: false,
    ShiFouZaiFenJianXianShiMingXi: false,
    ShiFouDaoRuWaiJie: false
  },
  dialog: {
    isShowDialog: false,
    type: "",
    title: "",
    submitTxt: ""
  }
});
const yuanQuType = ref<any>([]);
const hospitalLs = () => {
  // yuanQuType.value = params;
  GetAllYuanQuSel().then((res: any) => {
    yuanQuType.value = [];
    res.Data?.map((item: string) => {
      let objLs = {
        value: item,
        label: item
      };
      yuanQuType.value.push(objLs);
    });
    if (state.dialog.type === "add") {
      state.ruleForm.SuoShuYuanQu = [];
      state.ruleForm.SuoShuYuanQu = yuanQuType.value.map((item: any) => item.value);
    }
  });
};
const feiYongLeiBieType = ref<any>([]);
const getFeiYongLeiBieSel = () => {
  GetFeiYongLeiBieSel().then((res: any) => {
    feiYongLeiBieType.value = [];
    res.Data.map(item => {
      let objLs = {
        value: item.ZiDianZhiNeiRong,
        label: item.ZiDianZhiNeiRong
      };
      feiYongLeiBieType.value.push(objLs);
    });
  });
};
const convertStringToArray = str => {
  let arr = str?.split(";");
  arr = arr?.map(item => item.trim());
  arr = arr?.filter(item => {
    // 过滤掉空字符串
    if (item === "") return false;
    return !/^\s*$/?.test(item);
  });
  return arr;
};
// 打开弹窗s
const openDialog = (type: string, row: any) => {
  state.dialog.isShowDialog = true;
  nextTick(() => {
    hospitalLs();
    getFeiYongLeiBieSel();
    if (type === "edit") {
      state.ruleForm = deepCopy(row);
      state.dialog.title = "修改组合项目";
      state.dialog.submitTxt = "确 定";
      state.ruleForm.SuoShuYuanQu = convertStringToArray(state.ruleForm.SuoShuYuanQu);
      //todo 查询的时候的字段和新增的时候的字段不一致（名字）
      // 新增的时候会多出一个 ChengBenJia 这个字段  是因为 表格的是ChengBenJia 这个字段
      state.ruleForm.ChengBenJian = row.ChengBenJia;
      state.ruleForm.ShiFouQiYong = row.ShiFouQiYong === "是";
      state.ruleForm.ShiFouZongjianZhanShi = row.ShiFouZongjianZhanShi === "是";
      state.ruleForm.ShiFouWeiXinZhanShi = row.ShiFouWeiXinZhanShi === "是";
      state.ruleForm.ShiFouZaiFenJianXianShiMingXi = row.ShiFouZaiFenJianXianShiMingXi === "是";
      state.ruleForm.ShiFouDaoRuWaiJie = row.ShiFouDaoRuWaiJie === "是";
      state.dialog.type = "edit";
    } else {
      state.dialog.title = "新增组合项目";
      state.dialog.submitTxt = "确 定";
      state.dialog.type = "add";
      state.ruleForm.ShiYongXingBie = "不限";
      state.ruleForm.BaoGaoSuoShuFenLei = useIntegratedProject().baoGao;
    }
  });
};
// 关闭弹窗
const closeDialog = () => {
  state.dialog.isShowDialog = false;
  nextTick(() => {
    roleDialogFormRef.value.resetFields();
  });
  emit("refresh");
};
// 取消
const onCancel = () => {
  closeDialog();
};
// 输入框的校验
const inputChange = (data: string | number) => {
  let logData: string | number;
  logData = data
    .replace(/[^\d.]/g, "")
    .replace(/\.{2,}/g, "")
    .replace(/^\./g, "")
    .replace(".", "$#$")
    .replace(/\./g, "")
    .replace("$#$", ".");
  return logData;
};

const inputChangeLs = (data: string | number, prop: string) => {
  state.ruleForm[prop] = inputChange(data);
};

const returnObj = () => {
  let obj = {
    ...state.ruleForm,
    KeShiID: useIntegratedProject().keShiId,
    ShenQingDanID: useIntegratedProject().shenQingDanID,
    SuoShuYuanQu: state.ruleForm.SuoShuYuanQu.join(";"),
    ShiFouQiYong: state.ruleForm.ShiFouQiYong === true ? "是" : "否",
    ShiFouZongjianZhanShi: state.ruleForm.ShiFouZongjianZhanShi === true ? "是" : "否",
    ShiFouWeiXinZhanShi: state.ruleForm.ShiFouWeiXinZhanShi === true ? "是" : "否",
    ShiFouZaiFenJianXianShiMingXi: state.ruleForm.ShiFouZaiFenJianXianShiMingXi === true ? "是" : "否",
    ShiFouDaoRuWaiJie: state.ruleForm.ShiFouDaoRuWaiJie === true ? "是" : "否",
    KeShiFenChengJia: state.ruleForm.KeShiFenChengJia ? +state.ruleForm.KeShiFenChengJia : 0,
    // todo ?
    ChengBenJian: state.ruleForm.ChengBenJian ? +state.ruleForm.ChengBenJian : 0,
    YouHuiJian: state.ruleForm.YouHuiJian ? +state.ruleForm.YouHuiJian : 0,
    DanJian: state.ruleForm.DanJian ? +state.ruleForm.DanJian : 0,
    ZuHeXiangMuMingCheng: state.ruleForm.ZuHeXiangMuMingCheng ? state.ruleForm.ZuHeXiangMuMingCheng : "",
    ShiYongXingBie: state.ruleForm.ShiYongXingBie ? state.ruleForm.ShiYongXingBie : "",
    TiShiXinXi: state.ruleForm.TiShiXinXi ? state.ruleForm.TiShiXinXi : "",
    ZhengChangMiaoShu: state.ruleForm.ZhengChangMiaoShu ? state.ruleForm.ZhengChangMiaoShu : "",
    MoRenShenHeZhe: state.ruleForm.MoRenShenHeZhe ? state.ruleForm.MoRenShenHeZhe : "",
    MoRenJianChaZhe: state.ruleForm.MoRenJianChaZhe ? state.ruleForm.MoRenJianChaZhe : "",
    PYM: state.ruleForm.PYM ? state.ruleForm.PYM : "",
    YiXueMingCheng: state.ruleForm.YiXueMingCheng ? state.ruleForm.YiXueMingCheng : "",
    YiXueJianMa: state.ruleForm.YiXueJianMa ? state.ruleForm.YiXueJianMa : "",
    WaiJieBianMa: state.ruleForm.WaiJieBianMa ? state.ruleForm.WaiJieBianMa : "",
    HISKeShiDaiMa: state.ruleForm.HISKeShiDaiMa ? state.ruleForm.HISKeShiDaiMa : "",
    HISKeShiMingCheng: state.ruleForm.HISKeShiMingCheng ? state.ruleForm.HISKeShiMingCheng : "",
    BaoGaoSuoShuFenLei: state.ruleForm.BaoGaoSuoShuFenLei ? state.ruleForm.BaoGaoSuoShuFenLei : "",
    FeiYongLeiBie: state.ruleForm.FeiYongLeiBie ? state.ruleForm.FeiYongLeiBie : "",
    GuoBiaoDaiMa: state.ruleForm.GuoBiaoDaiMa ? state.ruleForm.GuoBiaoDaiMa : "",
    ShangJiGuoBiaoDaiMa: state.ruleForm.ShangJiGuoBiaoDaiMa ? state.ruleForm.ShangJiGuoBiaoDaiMa : "",
    ShangJiGuoBiaoMingCheng: state.ruleForm.ShangJiGuoBiaoMingCheng ? state.ruleForm.ShangJiGuoBiaoMingCheng : "",
    BeiZhu1: state.ruleForm.BeiZhu1 ? state.ruleForm.BeiZhu1 : "",
    BeiZhu2: state.ruleForm.BeiZhu2 ? state.ruleForm.BeiZhu2 : "",
    BeiZhu3: state.ruleForm.BeiZhu3 ? state.ruleForm.BeiZhu3 : "",
    JianChaZhiBiaoYiYi: state.ruleForm.JianChaZhiBiaoYiYi ? state.ruleForm.JianChaZhiBiaoYiYi : ""
  };
  return obj;
};
// 提交
const onSubmit = () => {
  roleDialogFormRef.value!.validate(async valid => {
    if (!valid) return;
    console.log(state.dialog.type, "state.dialog.type");
    console.log(state.ruleForm, "state.ruleForm");
    if (state.dialog.type === "add") {
      let obj = returnObj();
      for (let key in obj) {
        if (obj[key] === undefined || obj[key] === null) {
          obj[key] = "";
        }
      }
      PostZuHeXiangMuAdd(obj).then(async (res: any) => {
        if (res.Success === 0) {
          console.log(res, "新增成功");
          ElMessage.success({ message: `${state.dialog.title}成功！` });
          await useIntegratedProject().getJianSuoZuHeXiangMuSel();
          closeDialog();
          emit("refresh");
        } else {
          ElMessage.error({ message: `${state.dialog.title}失败！` });
        }
      });
    } else {
      // console.log("修改");
      // console.log(state.ruleForm.ruleForm);
      // let obj = {
      //   ...state.ruleForm,
      //   KeShiID: useIntegratedProject().keShiId,
      //   ShenQingDanID: useIntegratedProject().shenQingDanID,
      //   SuoShuYuanQu: state.ruleForm.SuoShuYuanQu.join(";"),
      //   ShiFouQiYong: state.ruleForm.ShiFouQiYong === true ? "是" : "否",
      //   ShiFouZongjianZhanShi: state.ruleForm.ShiFouZongjianZhanShi === true ? "是" : "否",
      //   ShiFouWeiXinZhanShi: state.ruleForm.ShiFouWeiXinZhanShi === true ? "是" : "否",
      //   ShiFouZaiFenJianXianShiMingXi: state.ruleForm.ShiFouZaiFenJianXianShiMingXi === true ? "是" : "否",
      //   ShiFouDaoRuWaiJie: state.ruleForm.ShiFouDaoRuWaiJie === true ? "是" : "否",
      //   KeShiFenChengJia: state.ruleForm.KeShiFenChengJia ? +state.ruleForm.KeShiFenChengJia : 0,
      //   ChengBenJian: state.ruleForm.ChengBenJian ? +state.ruleForm.ChengBenJian : 0,
      //   YouHuiJian: state.ruleForm.YouHuiJian ? +state.ruleForm.YouHuiJian : 0,
      //   DanJian: state.ruleForm.DanJian ? +state.ruleForm.DanJian : 0
      // };
      PutZuHeXiangMuUpdate(returnObj()).then(async (res: any) => {
        if (res.Success === 0) {
          ElMessage.success({ message: `${state.dialog.title}成功！` });
          await useIntegratedProject().getJianSuoZuHeXiangMuSel();
          closeDialog();
          emit("refresh");
          // useIntegratedProject().getJianSuoZuHeXiangMuSel();
        } else {
          ElMessage.error({ message: `${state.dialog.title}失败！` });
        }
      });
    }
  });
};
watch(
  () => {
    return state.ruleForm.ZuHeXiangMuMingCheng;
  },
  () => {
    if (state.ruleForm.ZuHeXiangMuMingCheng) {
      state.ruleForm.PYM = pinyin(state.ruleForm?.ZuHeXiangMuMingCheng, {
        pattern: "first",
        toneType: "none"
      })
        .toUpperCase()
        .replace(/\s/g, "");
    }
  }
);
const ZuHeXiangMuMingChengRef = ref();
const openDialogLs = () => {
  nextTick(() => {
    if (ZuHeXiangMuMingChengRef.value) {
      ZuHeXiangMuMingChengRef.value.focus();
    }
  });
};
const [DanJiaRef, ZuHeXiangMuMingChengKey] = useFocusInput();
const [YouHuiJiaRef, DanJiaKey] = useFocusInput();
const [ChengBenJianRef, YouHuiJiaKey] = useFocusInput();
const [KeShiFenChengJiaRef, ChengBenJianKey] = useFocusInput();
const [ShiYongXingBieRef, KeShiFenChengJiaKey] = useFocusInput();
const [BaoGaoSuoShuFenLeiRef, PYMKey] = useFocusInput();
const [ZhengChangMiaoShuRef, TiShiXinXiKey] = useFocusInput();
const [MoRenJianChaZheRef, ZhengChangMiaoShuKey] = useFocusInput();
const [MoRenShenHeZheRef, MoRenJianChaZheKey] = useFocusInput();
const [YiXueMingChengRef, MoRenShenHeZheKey] = useFocusInput();
const [YiXueJianMaRef, YiXueMingChengKey] = useFocusInput();
const [WaiJieBianMaRef, YiXueJianMaKey] = useFocusInput();
const [HISKeShiDaiMaeRef, WaiJieBianMaKey] = useFocusInput();
const [FeiYongLeiBieRef, HISKeShiDaiMaKey] = useFocusInput();
const [GuoBiaoDaiMaRef, HISKeShiMingChengKey] = useFocusInput();
const [ShangJiGuoBiaoDaiMaRef, GuoBiaoDaiMaKey] = useFocusInput();
const [SuoShuYuanQuRef, ShangJiGuoBiaoDaiMaKey] = useFocusInput();
const [BeiZhu2Ref, BeiZhu1Key] = useFocusInput();
const [BeiZhu3Ref, BeiZhu2Key] = useFocusInput();
const [ShangJiGuoBiaoMingChengRef, BeiZhu3Key] = useFocusInput();
const [JianChaZhiBiaoYiYiRef, ShangJiGuoBiaoMingChengKey] = useFocusInput();
const [ShiFouQiYongRef, JianChaZhiBiaoYiYiKey] = useFocusInput();

// 暴露变量
defineExpose({
  openDialog
});
</script>

<style scoped lang="scss">
.system-role-dialog-container {
  .el-form-ls {
    height: 50vh;
    overflow: scroll;
    .el-form-new {
      height: 100%;
    }
  }
  :deep(.el-form-item) {
    margin-bottom: 0;
  }
}
.switch-all {
  :deep(.el-form-item__content) {
    margin-left: 0 !important;
  }
}
.switch-ls {
  --el-switch-on-color: #13ce66;
  --el-switch-off-color: #ff4949;
}
</style>
